define(["require", "exports"], function (require, exports) {
    "use strict";
    function addFirstSlash(string) {
        return string[0] === "/" ? string : "/" + string;
    }
    exports.addFirstSlash = addFirstSlash;
    function removeLastSlash(string) {
        return string.replace(/\/+$/, "");
    }
    exports.removeLastSlash = removeLastSlash;
    function concatUrl(frontUrl, behindUrl) {
        return this.removeLastSlash(frontUrl) + this.addFirstSlash(behindUrl);
    }
    exports.concatUrl = concatUrl;
    var CountToRun = (function () {
        function CountToRun(callback, scope) {
            this.count = 0;
            this.callback = null;
            this.scope = null;
            callback ? this.callback = callback : null;
            scope ? this.scope = scope : null;
        }
        CountToRun.prototype.setCallback = function (callback) {
            this.callback = callback;
        };
        CountToRun.prototype.setScope = function (scope) {
            scope ? this.scope = scope : null;
        };
        CountToRun.prototype.setCount = function (count) {
            this.count = count;
        };
        CountToRun.prototype.getCount = function () {
            return this.count;
        };
        CountToRun.prototype.plus = function () {
            if (++(this.count) === 0) {
                this.emit();
            }
        };
        CountToRun.prototype.minus = function () {
            if (--(this.count) === 0) {
                this.emit();
            }
        };
        CountToRun.prototype.emit = function () {
            if (this.scope) {
                this.callback.bind(this.scope)();
            }
            else {
                this.callback();
            }
        };
        return CountToRun;
    }());
    exports.CountToRun = CountToRun;
    function DateFormat(date, fmt) {
        var o = {
            "M+": date.getMonth() + 1,
            "d+": date.getDate(),
            "h+": date.getHours(),
            "m+": date.getMinutes(),
            "s+": date.getSeconds(),
            "q+": Math.floor((date.getMonth() + 3) / 3),
            "S": date.getMilliseconds()
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
    exports.DateFormat = DateFormat;
});
